package easy;

public class Solution_LCS_01 {
    public int leastMinutes(int n) {
        int count = 0, num = 1;
        while (num < (n - 1)) {
            num <<= 1;
            count++;
        }
        int hid = 1 << count;
        int res = count + (n + hid - 1) / hid;
        if (count > 0) {
            hid = 1 << (count - 1);
            return Math.min(count - 1 + (n + hid - 1) / hid, res);
        } else {
            return res;
        }

        /*int count = 0, num = 1;
        while (num < n) {
            num <<= 1;
            count++;
        }
        int res = 0;
        for (int i = 0; i <= count; i++) {
            int offset = 1 << i;
            int temp = i + (n + offset - 1) / (offset);
            if (res == 0 || temp < res) {
                res = temp;
            }
        }
        return res;*/
    }

    public static void main(String[] args) {
        Solution_LCS_01 model = new Solution_LCS_01();
        System.out.println(model.leastMinutes(1)); // 1
        System.out.println(model.leastMinutes(2)); // 2
        System.out.println(model.leastMinutes(4)); // 3
        System.out.println(model.leastMinutes(5)); // 4
        System.out.println(model.leastMinutes(7)); // 4
    }
}
